package examples.codequality.app;

import examples.codequality.domain.User;
import examples.codequality.domain.UserGateway;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.async.DeferredResult;

import java.util.UUID;

/**
 * @author baigod
 */
@Component
public class UserGetQryExe {

    @Resource
    UserGateway userGateway;

    public void execute(String id, DeferredResult<ResponseEntity<User>> response) {
        User user = userGateway.get(UUID.fromString(id));

        if (null == user) {
            response.setErrorResult(ResponseEntity.notFound());
        } else {
            response.setResult(ResponseEntity.ok(user));
        }

    }
}